Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 29, 2025

🌱 A new release!

6.20.0 (2025-09-17)

The MongoDB Node.js team is pleased to announce version 6.20.0 of the mongodb package!

Release Notes

Collection and Db objects now provide references to their Db and MongoClient

import { MongoClient } from 'mongodb';

const client = new MongoClient(process.env.MONGODB_URI);
const db = client.db('test');
assert(db.client === client); // returns the MongoClient associated with the Db object
const collection = db.collection('test');
assert(collection.db === db); // returns the Db associated with the Collection object

Hint is supported with unacknowledged writes for delete, update and findAndModify commands on servers that support hint

The driver no longer throws errors when hint is provided to unacknowledged writes for delete, update and findAndModify commands in the following circumstances:

  • No error is thrown for update commands.
  • No errors are thrown for delete and findAndModify commands on servers >=4.4.

ServerCapabilities and ReadPreference.minWireVersion are deprecated

Neither the ServerCapabilities class nor the ReadPreference.minWireVersion property were ever intended for public use and, internally, are effectively dead code with the driver's minimum supported server version being 4.2.

Driver info and metadata MongoClient options have been deprecated.

These will be made internal in a future major release:

  • driverInfo
  • additionalDriverInfo
  • metadata
  • extendedMetadata

CommandOperationOptions.retryWrites is deprecated

CommandOperationOptions.retryWrites is deprecated. This per‑command option has no effect; the Node.js driver only honors retryWrites when configured at the client level (MongoClient options) or via the connection string. Do not use this option on individual commands. There is no runtime behavior change because it was already ignored, but it will be removed in an upcoming major release and may cause type or build errors in code that references it. To control retryable writes, set retryWrites in MongoClient options or include retryWrites=true|false in the connection string.

ChangeStream .tryNext() now updates resumeToken to prevent duplicates after resume

When .tryNext() returns a change document, the driver now caches its resumeToken, aligning its behavior with .next() and the 'change' event. If .tryNext() returns null (no new changes), nothing is cached, which is unchanged from previous behavior.

Previously, .tryNext() did not update the resumeToken, so a resumable error could cause a resume from an older token and re-deliver already processed changes. With this release, resumes continue from the latest token observed via .tryNext(), preventing duplicates.

const changeStream = collection.watch([]);
while (true) {
  const change = await changeStream.tryNext(); // prior versions could return duplicates
  await scheduler.wait(1000);  // delay since tryNext() does not wait for changes
}

Applications that poll change streams with .tryNext() in non-blocking loops benefit directly. There are no API changes; if you previously tracked and passed resumeAfter or startAfter manually, you can now rely on the driver’s built-in token caching.

Huge thanks to @rkistner for bringing this bug to our attention and for sharing code to reproduce it. Huge thanks as well to @Omnicpie for investigating and implementing a fix.

Change Streams now resume on MongoServerSelectionError

When the driver encounters a MongoServerSelectionError while processing a Change Stream (e.g., due to a transient network issue or during an election), it now treats the error as resumable and attempts to resume using the latest cached resume token.

This applies to both iterator and event-emitter usage:

// Iterator form
const changeStream = collection.watch([]);
for await (const change of changeStream) {
  // process change
}
// Event-emitter form
const changeStream = collection.watch([]);
changeStream.on('change', (change) => {
  // process change
});

There are no API changes. If you previously caught MongoServerSelectionError and implemented manual resume logic, you can now rely on the driver’s built-in resume mechanism, which uses the cached resume token from the change event’s _id to continue without losing events.

Huge thanks to @grossbart for bringing this bug to our attention, investigating it and for sharing code to reproduce it!

MongoClient.appendMetadata() ignores duplicate metadata

MongoClient.appendMetadata() will no longer append metadata, if the metadata is a duplicate of metadata already appended to the MongoClient.

Features

Bug Fixes

Documentation

We invite you to try the mongodb library immediately, and report any issues to the NODE project.


@github-actions github-actions bot requested a review from a team as a code owner August 29, 2025 16:29
@github-actions github-actions bot force-pushed the release-please--branches--main--components--mongodb branch 6 times, most recently from 5ff9d45 to 71e2db5 Compare September 9, 2025 20:11
@github-actions github-actions bot force-pushed the release-please--branches--main--components--mongodb branch 4 times, most recently from 3b7e2bc to 101c737 Compare September 17, 2025 14:29
@github-actions github-actions bot force-pushed the release-please--branches--main--components--mongodb branch from 101c737 to fc9fbfd Compare September 17, 2025 15:13
@tadjik1
Copy link
Contributor

tadjik1 commented Sep 18, 2025

run release_notes

1 similar comment
@tadjik1
Copy link
Contributor

tadjik1 commented Sep 18, 2025

run release_notes

@tadjik1 tadjik1 merged commit 477140e into main Sep 18, 2025
9 of 10 checks passed
@tadjik1 tadjik1 deleted the release-please--branches--main--components--mongodb branch September 18, 2025 15:27
Copy link
Contributor Author

🤖 Created releases:

🌻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant